<%
var headerPart = {
%>
<script type="text/javascript">
    function viewComment(href){
        layer.open({
            type: 2,
            title: "查看评论",
            shadeClose: true,
            shade: 0.3,
            area: ['900px','550px'],
            content: href,
            btn: ['关闭'],
            yes: function(index, layero){
                layer.close(index);
            }
        });
        return false;
    }
    function page(n,s){
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
</script>
<% }; %>
<% layout("/layouts/micro.html",{headerSection:headerPart}){ %>
<div class="layui-fluid" style="padding: 5px!important;">
	<div class="layui-card">
		<form id="searchForm" action="${ctx}/cms/article/" method="post" class="layui-form layui-card-header layuiadmin-card-header-auto">
			<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
			<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">栏目：</label>
					<div class="layui-input-block">
						<#treeselect id="category" name="category.id" value="${article.category.id!}" labelName="category.name" labelValue="${article.category.name!}"
							title="栏目" url="/cms/category/treeData" module="article" notAllowSelectRoot="false" cssClass="input-small"/>
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label">标题：</label>
					<div class="layui-input-block">
						<input type="text" name="title" value="${article.title}" htmlEscape="false" maxlength="50" class="layui-input"/>
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-block">
						<#radio name="delFlag" value="${article.delFlag }" items="${@DictUtils.getDictList('cms_del_flag')}"/>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-enrollList-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</form>
		<div class="layui-card-body">
		<#message content="${message!}"/>
			<%if(shiro.hasPermission("cms:article:edit")){%>
			<div>
				<button class="layui-btn layui-btn-normal LAY_ADD_article_btn"><i class="layui-icon layui-icon-add-1"></i>添加</button>
			</div>
			<%}%>
			<table id="contentTable" class="layui-table" >
				<thead>
					<tr>
						<th style="text-align:center">栏目</th>
						<th style="text-align:center">标题</th>
						<th style="text-align:center">权重</th>
						<th style="text-align:center">点击数</th>
						<th style="text-align:center">发布者</th>
						<th style="text-align:center">更新时间</th>
						<th style="text-align:center">操作</th>
					</tr>
				</thead>
				<tbody>
				<%for(article in page.list){%>
					<tr>
						<td>${article.category.name}</td>
						<td>${@StringUtils.abbr(article.title,40)}</td>
						<td style="text-align:center">${article.weight}</td>
						<td style="text-align:center">${article.hits}</td>
						<td style="text-align:center">${article.user.name}</td>
						<td style="text-align:center">${article.updateDate,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
						<td style="text-align:center">
							<a class="layui-btn layui-btn-xs" href="${ctxFront}/view-${article.category.id}-${article.id}${@Global.getUrlSuffix()}" target="_blank">访问</a>
							<%if(shiro.hasPermission("cms:article:edit")){%>
								<%if(article.category.allowComment == '1'){%>
								<%if(shiro.hasPermission("cms:comment:view")){%>
									<a class="layui-btn layui-btn-xs" href="${ctx}/cms/comment/?module=article&contentId=${article.id}&delFlag=2" onclick="return viewComment(this.href);">评论</a>
								<%}%>
							<%}%>
								<a class="layui-btn layui-btn-xs" onclick="editArticle(${article.id})" href="javascript:void(0);">修改</a>
								<%if(shiro.hasPermission("cms:article:audit")){%>
									<a class="layui-btn layui-btn-danger layui-btn-xs" href="${ctx}/cms/article/delete?id=${article.id}${article.delFlag != '0'?'&isRe=true':''}&categoryId=${article.category.id}" onclick="return confirmx('确认要${article.delFlag != '0'?'发布':'删除'}该文章吗？', this.href)" >${article.delFlag != '0'?'发布':'删除'}</a>
								<%}%>
							<%}%>
						</td>
					</tr>
				<%}%>
				</tbody>
			</table>
			<div class="pagination">${page}</div>
		</div>
	</div>
</div>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        //添加
        $(".LAY_ADD_article_btn").click(function(){
            var index = layui.layer.open({
                title : "添加文章",
                type : 2,
                content : "${ctx}/cms/article/form?id=${article.id}&category.id=${article.category.id}&category.name=${article.category.name}",
                maxmin: true,
                area: ['100%', '100%'],
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#articleForm');
                    submit.trigger('click');
                    layer.close(index);
                },
                end:function(){
                    location.reload();
                }
            })
        })
    })
    var editArticle = function(id){
        var index = layui.layer.open({
            title : "修改文章",
            type : 2,
            content : "${ctx}/cms/article/form?id="+id,
            maxmin: true,
            area: ['100%', '100%'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#articleForm');
                submit.trigger('click');
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
</script>
<%}%>